package com.clstu.map;

import java.util.*;

public class MapMethod {
    public static void main(String[] args) {
         Map map=new HashMap();
         map.put("邓超","孙俪");
         map.put("王宝强","马蓉");
         map.put("宋吉","马蓉");
         map.put("刘令博",null);
         map.put(null,"刘亦菲");
         map.put("鹿晗","关晓彤");//增强for不能直接遍历map类型的对象
                                //因为没有实现Iterable接口
         Set keySet=map.keySet();//返回Set对象,得到所有的key
        for (Object o:keySet
             ) {
            System.out.println(o+"--"+map.get(o));
        }
        System.out.println("========er=======");
        Iterator iterator = keySet.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next+"--"+map.get(next));
        }
        System.out.println("============");
        Collection values=map.values();//返回Collection对象，所有的值
        for (Object o:values
             ) {
            System.out.println(o);
        }
        System.out.println("=================");
        Iterator iterator1=values.iterator();
        while (iterator1.hasNext()) {
            Object next =  iterator1.next();
            System.out.println(next);
        }
        System.out.println("==========");
        Set entrySet = map.entrySet();//返回set
        for (Object o:entrySet
             ) {
            //System.out.println(o);
            Map.Entry entry = (Map.Entry) o;
            System.out.println(entry.getKey()+"--"+entry.getValue());
        }
        Iterator iterator2=entrySet.iterator();
        System.out.println("======");
        while (iterator2.hasNext()) {
            Object next =  iterator2.next();
            Map.Entry entry = (Map.Entry) next;
            System.out.println(entry.getKey()+"  "+entry.getValue());
        }
        System.out.println("==========");

    }
}
